﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Clueless
{
    public partial class suggestion : Form
    {
        private delegate void CardDeckDelegate(CardDeck deck, String room);
        public event EventHandler<SuggestionEventArgs> SuggestSelected;
        public event EventHandler<EventArgs> CancelSelected;

        public suggestion()
        {
            InitializeComponent();
        }

        public void FillCrap(CardDeck deck, String room)
        {
            if (suggestWeaponComboBox.InvokeRequired)
                suggestWeaponComboBox.Invoke(new CardDeckDelegate(FillCrap), deck, room);
            else
            {
                suggestSuspectComboBox.Items.Clear();
                suggestWeaponComboBox.Items.Clear();

                foreach (Card c in deck.Cards)
                {
                    switch (c.CardType)
                    {
                        case CardType.Character:
                            suggestSuspectComboBox.Items.Add(c.Name);
                            break;
                        case CardType.Weapon:
                            suggestWeaponComboBox.Items.Add(c.Name);
                            break;

                    }
                }

                suggestRoomTextBox.Text = room;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void suggestButton_Click(object sender, EventArgs e)
        {
            SendSuggestionMessage(suggestSuspectComboBox.Text, suggestWeaponComboBox.Text, suggestRoomTextBox.Text);
        }

        private void suggestCancelButton_Click(object sender, EventArgs e)
        {
            SendCancelMessage();
        }


        /// <summary>
        /// Start Trun
        /// </summary>
        /// <param name="s"></param>
        private void SendCancelMessage()
        {
            this.Hide();
            EventArgs args = new EventArgs();
            OnCancelMessage(args);
        }
        public virtual void OnCancelMessage(EventArgs e)
        {
            EventHandler<EventArgs> handler = CancelSelected;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        /// <summary>
        /// Start Trun
        /// </summary>
        /// <param name="s"></param>
        private void SendSuggestionMessage(String c, String w, String r)
        {
            this.Hide();
            Console.WriteLine("Suggestion!  c:" + c + " w:" + w + " r:");
            SuggestionEventArgs args = new SuggestionEventArgs();
            args.character = c;
            args.weapon = w;
            args.room = r;
            OnSuggestionMessage(args);
        }
        public virtual void OnSuggestionMessage(SuggestionEventArgs e)
        {
            EventHandler<SuggestionEventArgs> handler = SuggestSelected;
            if (handler != null)
            {
                handler(this, e);
            }
        }

    }

    public class SuggestionEventArgs : EventArgs
    {
        public String character { get; set; }
        public String weapon { get; set; }
        public String room { get; set; }
    }
}
